package com.tao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tao.mapper.UserMapper;
import com.tao.pojo.User;
import com.tao.pojo.vo.Code;
import com.tao.pojo.vo.ResponseResult;
import com.tao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Override
    public Object edit(User admin) {
        String password = null;
//        ObjectUtils.isEmpty 意思是不成立的时候执行，也就是没值的时候执行
        if (!ObjectUtils.isEmpty(admin.getPassword())){
            admin.setPassword(passwordEncoder.encode(admin.getPassword()));
        }
        super.save(admin);
        return ResponseResult.success(Code.OK);
    }
}
